package com.example.helloworld;

public class FininalizationDemo {
    public static void main(String[] args) {
        Cake c1 = new Cake(1);
        Cake c2 = new Cake(2);
        Cake c3 = new Cake(3);

        c2 = c3 = null;
        System.gc(); // Call the garbage collector
    }
}

class Cake extends Object {
    private int id;
    public Cake(int id) {
        this.id = id;
        System.out.println("Cake " + id + " created.");
    }

    protected void finalize() throws Throwable {
        System.out.println("Cake " + id + " is being finalized.");
        super.finalize();
    }
}
